/*
 * ServiceAndFeedbackFragment.java
 * business
 *
 * Created by chentao on 2017/5/10.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.service;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.yidiandao.business.R;
import com.yidiandao.business.base.SuperBaseFragment;
import com.yidiandao.business.ui.adapter.HelpCenterAdapter;
import com.yidiandao.business.ui.service.feedback.FeedbackActivity;
import com.yidiandao.business.ui.service.helpcenter.HelpCenterActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.utils.UmengUtils;

import java.util.List;

/**
 * 服务与反馈
 */
public class ServiceFragment extends SuperBaseFragment
        implements ServiceContract.View, View.OnClickListener {

    private static final String TAG = ServiceFragment.class.getSimpleName();

    private Toolbar mToolbar;

    private RelativeLayout mRlHelpCenter;

    private RelativeLayout mRlFeedback;

    private ServiceContract.Presenter mPresenter;

    private ListView mListView;

    private HelpCenterAdapter mHelpCenterAdapter;

    public static ServiceFragment getInstance() {
        return new ServiceFragment();
    }

    @Override
    protected void initViews() {
        mListView = (ListView) mRootView.findViewById(R.id.list_view);

        View view = View.inflate(mActivity, R.layout.fragment_service_and_feedback_footer, null);
        mListView.addFooterView(view);

        mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        mRlHelpCenter = (RelativeLayout) view.findViewById(R.id.rl_helpCenter);
        mRlFeedback = (RelativeLayout) view.findViewById(R.id.rl_feedback);

        mHelpCenterAdapter = new HelpCenterAdapter(mActivity);
        mListView.setAdapter(mHelpCenterAdapter);
        initEvent();
    }

    @Override
    protected void startLoadData() {
        mPresenter.start();
    }

    private void initEvent() {
        mToolbar.setNavigationOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mActivity.finish();
                    }
                });

        mRlHelpCenter.setOnClickListener(this);
        mRlFeedback.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_service;
    }

    @Override
    public void setPresenter(ServiceContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return TAG;
    }

    @Override
    public void showToast(String text) {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_helpCenter:
                //帮助中心
                HelpCenterActivity.actionStart(mActivity);
                break;
            case R.id.rl_feedback:
                //意见反馈
                UmengUtils.onEvent(mActivity, R.string.umeng_feedback);
                FeedbackActivity.actionStart(mActivity);
                break;
        }
    }

    @Override
    public void setDisplayListItem(List<DisplayListItem> displayListItems) {
        mHelpCenterAdapter.setData(displayListItems);
    }

    @Override
    public void refreshContent(int result) {
        superRefreshLayoutState(result);
    }

    @Override
    public int checkResultObject(Object resultObject) {
        return superCheckListState(resultObject);
    }
}
